<?php

namespace App\Http\Controllers;

use App\Models\Diocese;
use App\Models\Parish;
use Illuminate\Support\Facades\Storage;

// use App\Models\District;
// use Illuminate\Http\Request;
// use GuzzleHttp\Client;

class TestController extends Controller
{
    //
    public function index()
    {

        // $dio = Diocese::find(12);
        // dump($dio->cathedral);

        $model = Diocese::has('cathedral')->get();
        $model->load('cathedral');
        return $model;
        dump($model);
        // $model = Diocese::query();
        // $model->provinceName()->get();
        // if (request()->input('name')) {
        //     $model->where('name', 'like', '%' . request()->input('name') . '%');
        // }
        
        // $ret = $model->get();
        // $ret->load('cathedral');
        // dump($ret);
        // return $ret;

        //写入省地址
//        $base = ['base_uri' => 'https://restapi.amap.com/v3/geocode/'];
        // $client = new Client();
//        $response = $client->request('GET', 'regeo',[
//            'key' => '0f148265b6015c137eeb3ab622f7e997',
//            'output' => 'JSON'
//        ]);
//        $url1 = 'https://restapi.amap.com/v3/geocode/regeo?';
//        $url = 'https://restapi.amap.com/v3/geocode/geo?';
//         $url = 'https://restapi.amap.com/v3/config/district?';
//         $arr = [
//             'key' => '0f148265b6015c137eeb3ab622f7e997',
// //            'subdistrict' => 1
// //            'address' => '中国',
// //            'batch' => true
// //            'location'=>'116.481488,39.990464',
//         ];
//         $response = $client->request('GET',$url.http_build_query($arr));
//         $resbody = json_decode($response->getBody()->getContents(),true);
//         $districts = $resbody['districts'][0]['districts'];
//         foreach ($districts as $d){
//             unset($d['citycode'],$d['districts']);
//             District::create($d);
//         }
//        $d = $districts[0];
//
//        dump($d);

//        dump($districts);
        return 'aaa';
    }

    public function t()
    {
        // $url = '/storage/uploads/2020-11-27/5fc0c5781cc95.png';
        $url = '/storage/uploads/2020-10-26/timgw.jpeg';
        $dir = config('filesystems.disks.uploadimg.url');
        $name = str_replace($dir,'',$url);
        dump($name);
        dump(Storage::disk('uploadimg')->exists($name));
        // Storage::disk('uploadimg')->delete($name);
    }

    public function amap(){
        $parishlist = Diocese::has('parishlist','>',1)->get();
        $parishlist->load('parishlist');
        // foreach($parishlist as $parish){
        //     dump($parish->parishlist);
        // }
        // dump($parishlist->toArray());
        return view('amap',['parishlist'=>$parishlist]);
    }
}
